package com.neusoft.controller;

import com.neusoft.feign.DeptFeignClient;
import com.neusoft.po.Dept;
import com.neusoft.po.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dept")
public class DeptController {
    // @Autowired
    // private RestTemplate restTemplate;
    // @Autowired
    // private DiscoveryClient discoveryClient;
    @Qualifier("com.neusoft.feign.DeptFeignClient")
    @Autowired
    private DeptFeignClient dfc;

    @GetMapping("/getDeptByNo/{deptno}")
    private ResponseBean<Dept> getDeptByNo(@PathVariable("deptno") Integer deptno){
        // List<ServiceInstance> list = discoveryClient.getInstances("provider-server");
        // ServiceInstance instance = list.get(0);
        // String url = "http://"+instance.getHost()+":"+instance.getPort()+"/dept/getDeptByNo/"+deptno;
        // ResponseBean rb = restTemplate.getForObject(url, ResponseBean.class);
        // return rb;
        // return null;

        return dfc.getDeptByNo(deptno);
    }
}
